package com.zxjbyte.yiyi.module.plugin.sse.api;

import com.zxjbyte.yiyi.framework.common.constant.HeaderMsg;
import com.zxjbyte.yiyi.framework.common.domain.message.StreamMessage;
import com.zxjbyte.yiyi.module.plugin.sse.session.SseSession;
import org.springframework.stereotype.Service;

/**
 * @Author zhangxingjia
 * @Date 2024/7/14 18:43
 * @Version: 1.0
 */
@Service
public class SseEmitterApiImpl implements SseEmitterApi{


    @Override
    public boolean sendOneMessage(String clientId, String userId, String message) {
        return SseSession.sendMessage(clientId, userId, StreamMessage.of(HeaderMsg.SEND_MESSAGE, message));
    }

    @Override
    public void broadcastMessage(String clientId, String message) {
        SseSession.broadcastMessage(clientId, StreamMessage.of(HeaderMsg.BROADCAST_MESSAGE, message));
    }

    @Override
    public void broadcastOnlineUsers(String clientId) {
        SseSession.broadcastOnlineUsersNumber(clientId);
    }

    @Override
    public Integer getOnlineUserCount(String clientId) {
        return SseSession.getOnlineUsersNumber(clientId);
    }
}
